<template>
  <div class="tab-control">
    <div class="tab-control-item"
         v-for="(item, index) in titles"
         :key="index"
         :class="{active: index === currentIndex}"
         @click="itemClick(index)"
    >
      <span>{{item}}</span>
    </div>
  </div>
</template>

<script>
import {ref} from 'vue'
export default {
  name: "TabControl",
  props: ['titles'],
  setup(props, {emit}) {
    const currentIndex = ref(0)
    const itemClick = index => {
      currentIndex.value = index
      emit('tabClick', index)
    }
    return {
      currentIndex, itemClick
    }
  }
}
</script>

<style scoped lang="scss">
.tab-control {
  display: flex;
  justify-content: space-around;
  color: var(--color-text);
  //黏住
  position: sticky;
  top: 45px;
  right: 0;
  height: 40px;
  line-height: 40px;
  background: #fff;
  z-index: 100;
  .tab-control-item {
    &.active {
      border-bottom: 3px solid var(--color-tint);
    }
    span {
      padding: 0 6px;
    }
  }
}
</style>